package cristiano.rodrigo.luiz.projetoandroidwn;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import cristiano.rodrigo.luiz.projetoandroidwn.GameDetailFragment.GameSalvoListener;

public class GameDetailActivity extends SherlockFragmentActivity implements GameSalvoListener{

	GameDetailFragment detalhe;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
		
		Game g = (Game)getIntent().getSerializableExtra("game");
		detalhe = GameDetailFragment.novoDetalhe(g);
		detalhe.setListener(this); 
		
		FragmentTransaction transacao = getSupportFragmentManager().beginTransaction();
		transacao.replace(android.R.id.content, detalhe, "detail");
		transacao.commit();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getSupportMenuInflater().inflate(R.menu.fragment_game_detail, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		if (item.getItemId() == R.id.action_save){
			setResult(RESULT_OK);
			detalhe.salvar();
		}
		
		return super.onMenuItemSelected(featureId, item);
	}
	
	@Override
	public void aoSalvarGame(Game g) {
		finish();
	}

}
